class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        unordered_set<int> rowSet;
        unordered_set<int> colSet;
        for (int idxRow = 0; idxRow < matrix.size(); idxRow++) {
            for (int idxCol = 0; idxCol < matrix[idxRow].size(); idxCol++) {
                if (matrix[idxRow][idxCol] == 0) {
                    CheckNum(idxRow, rowSet);
                    CheckNum(idxCol, colSet);
                }
            }
        }
        /* 遍历替换 */
        for (int idxRow = 0; idxRow < matrix.size(); idxRow++) {
            for (int idxCol = 0; idxCol < matrix[idxRow].size(); idxCol++) {
                if ((rowSet.count(idxRow) == 1) || (colSet.count(idxCol) == 1)) {
                    matrix[idxRow][idxCol] = 0;
                }
            }
        }
    }

    void CheckNum(int index, unordered_set<int>& numSet)
    {
        if (numSet.find(index) == numSet.end()) {
            numSet.insert(index);
        }
        return;
    }
};